home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / SAS-C / sc655pch / mount / mountv37.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-11  |  1.8 KB  |  63 lines

  1. /* Copyright (c) 1994 Doug Walker, Raleigh, NC */
  2. /* All Rights Reserved. */
  3. #include <dos/dos.h>
  4. #include <exec/memory.h>
  5. #include <exec/execbase.h>
  6. #include <proto/exec.h>
  7. #include <proto/dos.h>
  8.  
  9. /* Dismount a volume */
  10. void DisMount(struct DeviceList *volume)
  11. {
  12.  
  13.    /* Check for any outstanding locks; if present, can't dismount */
  14.    if(volume == NULL || volume->dl_Lock != NULL) return;
  15.  
  16.    RemDosEntry((struct DosList *)volume);
  17.    FreeDosEntry((struct DosList *)volume);
  18. }
  19.  
  20. /* Mount a volume with the given name; route all handler */
  21. /* messages to the given port.                           */
  22. struct DeviceList *Mount(char *name, struct MsgPort *port)
  23. {
  24.    struct DeviceList *volume;
  25.    struct DosList *dlist;
  26.  
  27.    if(name == NULL || port == NULL) return NULL;
  28.  
  29.    while(!(dlist = AttemptLockDosList(LDF_VOLUMES|LDF_WRITE)))
  30.    {
  31.       /* Can't lock the DOS list.  Wait a second and try again. */
  32.       Delay(50);
  33.    }
  34.    volume = (struct DeviceList *)FindDosEntry(dlist, name, LDF_VOLUMES);
  35.    if(volume) RemDosEntry((struct DosList *)volume);
  36.    UnLockDosList(LDF_VOLUMES|LDF_WRITE);
  37.  
  38.    if(!volume && !(volume = (struct DeviceList *)MakeDosEntry(name, DLT_VOLUME)))
  39.    {
  40.       return NULL;
  41.    }
  42.  
  43.    /* Give the volume a default date... of course, you can change it later */
  44.    volume->dl_VolumeDate.ds_Days   = 3800L;
  45.    volume->dl_VolumeDate.ds_Minute =
  46.    volume->dl_VolumeDate.ds_Tick   = 0L;
  47.    volume->dl_Lock = NULL;
  48.  
  49.    /* Now we can own the volume by giving it our task id */
  50.    volume->dl_Task = port;
  51.    volume->dl_DiskType = ID_DOS_DISK;
  52.  
  53.    while(!(dlist = AttemptLockDosList(LDF_VOLUMES|LDF_WRITE)))
  54.    {
  55.       /* Oops, can't lock DOS list.  Wait 1 second and retry. */
  56.       Delay(50);
  57.    }
  58.    AddDosEntry((struct DosList *)volume);
  59.    UnLockDosList(LDF_VOLUMES|LDF_WRITE);
  60.    return volume;
  61. }
  62.  
  63.